$(document).ready(function () {
    jQuery('.dropdown').each(function () {
        var t = jQuery(this);
        t.find('a.dropdown_label').click(function () {
            if (!t.hasClass('open')) {
                var h = t.height();
                t.find('ul').show().css({top: h + 2 + 'px'});
                t.addClass('open');
            } else {
                t.find('ul').hide();
                t.removeClass('open');
            }
            return false;
        });

    });

    jQuery(document).click(function () {
        jQuery('.dropdown').removeClass('open').find('ul').hide();
    });


});

function searchorder(id) {
    if (id) {
        $("#ordersearchID").val(id);
        $('#Newsearch').submit();
    }
}

function showOrderlistSell(id, orderid,tradeid) {
    $.post("/orderlist/ajaxbutton", {"op": "showOrderlistSell", "id": id},
        function (data) {
            if (data.length == 0) {
                alert("没有数据！");
                return;
            } else {
                var tmp = '';
				var ordergoods = data.res;
                for (var i = 0; i < ordergoods.length; i++) {
                    tmp += '<tr>'
                    //var style = 'style="width: 100%; overflow:hidden;white-space:nowrap; text-overflow:ellipsis;"';
					var style='';
                    var stocktmp = "";
                    var datastock = ordergoods[i].stock;
                    var waitnum="";
                    if (datastock.length > 0) {
                        stocktmp += '<div class="newstocklist">';
                        for (var s = 0; s < datastock.length; s++) {
							if(datastock[s].in_transit>0)
							{
								    waitnum="<li>";
									waitnum+= "在途"+datastock[s].in_transit;
									if(datastock[s].waitday){
										waitnum+= "&nbsp;&nbsp;["+datastock[s].waitday+"]";
									}
									waitnum+="</li>";
							}else{
									waitnum = "";
							}
							if(datastock[s].storage_id==1 || datastock[s].storage_id==2){
								stocktmp += "<ul><li><font color=\"red\">" + datastock[s].stock + "</font></li><li>" + datastock[s].storage_name + "</li> <li>" + datastock[s].positions + "</li>"+waitnum+"</ul>";
							}
                        }
                        stocktmp += "</div>";
                    }

                    tmp += "<td height=58><a href='/product/showproduct?goods_id=" + ordergoods[i].goods_id + "' target=_thank><font color=\"#6666FF\">" + ordergoods[i].goods_sn + "</font></a></td><td " + style + " title=" + ordergoods[i].goods_name + ">" + ordergoods[i].goods_name + "</td><td>" + ordergoods[i].goods_number + "</td><td>" + ordergoods[i].goods_price + "</td><td>" + ordergoods[i].costprice + "</td><td>" + ordergoods[i].goods_amount + "</td> <td>" + stocktmp + "</td>";
                    tmp += "</tr>";

                }
				var orderdata = data.order;
				tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>+ 商品收入</td><td valign=\"top\" align='right'>" + orderdata.allmoney + " RMB</td></tr>";
                tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>+ 运费收入</td><td  valign=\"top\" align='right'> " + orderdata.shipping_fee + " RMB</td></tr>";
                //tmp+="<tr><td colspan=\"6\" align='right'>包装费用</td><td colspan=\"3\" valign=\"top\">"+orderdata.pack_fee+" RMB</td></tr>";
                tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>- 支付费用</td><td valign=\"top\" align='right'> " + orderdata.pay_fee + " RMB</td></tr>";
                tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>- 平台费用</td><td  valign=\"top\" align='right'> " + orderdata.platform_fee + " RMB</td></tr>";
                tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>- 商品成本</td><td  valign=\"top\" align='right'> " + orderdata.cosprice + " RMB</td></tr>";
			
				tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>- 运费成本</td><td  valign=\"top\" align='right'>" + orderdata.shippingfee + " RMB</td></tr>";
			
				
                tmp += "<tr id=ordersellsubtotal style=display:none><td colspan=\"6\" align='right'>小计</td><td  valign=\"top\" align='right'>" + orderdata.subtotal + " RMB</td></tr>";
                $("#showorderlistdata").html(tmp);
                $("#sshoworderSN").html("订单号 <a href=\"/orderlist/editorder?order_id="+id+"\" target=_thank><font color='#6666FF'>"+orderid + "</font></a>  交易号 "+tradeid);
                $('#showorder').modal('show');
            }

        }, "json");
}

function showcountrytable() {
    $('#showcountry').modal('show');
}
function showordersellsubtotal() {
    $('[id=ordersellsubtotal]').show();

}

function selectCountry(t) {
    var winWidth = window.screen.width;
    var winHeight = window.screen.height;
    var newWidth = 900;
    var newHeight = 900;
    var url = "/order/ajaxbutton?op=selectCountry&type="+t;
    window.open(url, '_blank', 'height=' + newHeight + ',width=' + newWidth + ',top=10,left=' + (winWidth - newWidth) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
}

function selectShop() {
    var winWidth = window.screen.width;
    var winHeight = window.screen.height;
    var newWidth = 900;
    var newHeight = 650;
    var url = "/order/ajaxbutton?op=selectShop";
    window.open(url, '_blank', 'height=' + newHeight + ',width=' + newWidth + ',top=10,left=' + (winWidth - newWidth) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
}
function selectZipcode() {
    var winWidth = screen.width;
    var winHeight = screen.height;
    var newWidth = 900;
    var newHeight = 650;
    var url = "/order/ajaxbutton?op=selectZipcode";
    window.open(url,'_blank','height='+newHeight+',width='+newWidth+',top=10,left='+(winWidth-newWidth)/2+',toobar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
}
function selectLogistics() {
    var winWidth = screen.width;
    var winHeight = screen.height;
    var newWidth = 900;
    var newHeight = 650;
    var url = "/order/ajaxbutton?op=selectLogistics";
    window.open(url,'_blank','height='+newHeight+',width='+newWidth+',top=10,left='+(winWidth-newWidth)/2+',toobar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
}


/***************************
 选择订单号提交交运信息
 ** type 交运对象 如：ups  sf CNE 等
 *****************************/
function upsexpress(type) {
    var str = selectallpro();
    //验证是否已经分仓，若未分仓，则不允许操作
    $.post("/orderlist/ajaxbutton", {"op": "doSeparateWarehouse","str":str},
        function(data){
            if(data.code==200)
            {

                var submit_act = new Array();
                submit_act['sfexpress'] = "/order/ajaxbutton?op=saveexpress",
                submit_act['UPS'] = "/order/ajaxbutton?op=saveexpress",
                submit_act['DHL'] = "/expressshipment/ajaxbutton?op=DHLexpress",
                submit_act['UBI'] = "/expressshipment/ajaxbutton?op=UBIexpress",
                submit_act['CNE'] = "/expressshipment/ajaxbutton?op=CNEexpress",
                submit_act['YIDA'] = "/expressshipment/ajaxbutton?op=YIDAexpress",
                submit_act['WUY'] = "/order/ajaxbutton?op=WUYexpress";
				submit_act['JIAC'] = "/expressshipment/ajaxbutton?op=JIACexpress";
				submit_act['ZTO'] = "/expressshipment/ajaxbutton?op=ZTOexpress";
                $("#attributeform").attr("action", submit_act[type]);
                if (str != false) {
                    if(type=='CNE'){
                        $("#cnetype_tr").show();
                        $("#sprintform").text('');
                        $("#sprintform").text('CNE待交运订单编号');
                    }else{
                        $("#cnetype_tr").hide();
                    }
                    if(type=="UPS"){
                        $("#sprintform").text('');
                        $("#sprintform").text('UPS待交运订单编号');
                    }
                    if(type=="sfexpress"){
                        $("#sprintform").text('');
                        $("#sprintform").text('顺丰待交运订单编号');
                    }
                    if(type=="DHL"){
                        $("#sprintform").text('');
                        $("#sprintform").text('DHL待交运订单编号');
                    }
                    if(type=="UBI"){
                        $("#sprintform").text('');
                        $("#sprintform").text('UBI待交运订单编号');
                    }
                    if(type=="YIDA"){
                        $("#sprintform").text('');
                        $("#sprintform").text('日本邮政待交运订单编号');
                    }
					if(type=="ZTO"){
                        $("#sprintform").text('');
                        $("#sprintform").text('中通快递待交运订单编号');
                    }
					if(type=="JIAC"){
						$("#jiactype_tr").show();
                        $("#sprintform").text('');
                        $("#sprintform").text('佳成物流待交运订单编号');
                    }else{
						$("#jiactype_tr").hide();
					}
                    if(type=="WUY"){
                        $("#sprintform").text('');
                        $("#sprintform").text('无忧物流待交运订单编号');
                    }


                    if(type=='WUY'){
                        var Num="";
                        for(var i=0;i<11;i++)
                        {
                            Num+=Math.floor(Math.random()*10);
                        }
                        $("#kdnumber").val(Num);
                        $("#wuytype_tr").show();
                    }else{
                        $("#wuytype_tr").hide();
                    }

                    $("#orderlistst").val(str);
                    $("#type").val(type);
                    $('#expressform').modal('show');
                }
            }else{
                alert(data.msg);return false;
            }
        },"json");
}

function saveproduct() {
    var name = $("#name").val();
    if (name == "") {
        $("#namerr").html("<font color=red>请输入名称</font>");
        $("#name").focus();
        return;
    }
	var types = $("#types").val();
    if (types == "") {
        alert("请选择运费的计算方式！");
        $("#types").focus();
        return;
    }
    var filed13 = $("#filed13").val();
    if (filed13 == "9999") {
        $("#filed13err").html("<font color=red>请选择优先级</font>");
        $("#filed13").focus();
        return;
    }
    AWS.ajax_post($('#theFrom'));
}


//复制 粘贴  

function getCustomerInfo() {
    var textToClipboard = "Name:" + editForm.consignee.value + "\r\n" + "Address:" + editForm.address.value + "\r\n" + "Address2:" + editForm.address2.value + "\r\n" + "City:" + editForm.city.value + "\r\n" + "State:" + editForm.province.value + "\r\n" + "Country:" + editForm.country.value + "\r\n" + "Postal code:" + editForm.zipcode.value + "\r\n" + "Tel1:" + editForm.tel.value + "\r\n" + "Tel2:" + editForm.mobile.value + "\r\n" + "E-mail:" + editForm.email.value;

    var success = true;
    if (window.clipboardData) { // Internet Explorer
        window.clipboardData.setData("Text", textToClipboard);
    }
    else {
        // create a temporary element for the execCommand method
        var forExecElement = CreateElementForExecCommand(textToClipboard);
        /* Select the contents of the element
         (the execCommand for 'copy' method works on the selection) */
        SelectContent(forExecElement);
        var supported = true;
        // UniversalXPConnect privilege is required for clipboard access in Firefox
        try {
            if (window.netscape && netscape.security) {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }
            // Copy the selected content to the clipboard
            // Works in Firefox and in Safari before version 5
            success = document.execCommand("copy", false, null);
        }
        catch (e) {
            success = false;
        }
        // remove the temporary element
        document.body.removeChild(forExecElement);
    }

    if (success) {

    }
    else {
        alert("Your browser doesn't allow clipboard access!");
    }
}
function CreateElementForExecCommand(textToClipboard) {
    var forExecElement = document.createElement("div");
    forExecElement.style.position = "absolute";
    forExecElement.style.left = "-10000px";
    forExecElement.style.top = "-10000px";
    forExecElement.textContent = textToClipboard;
    document.body.appendChild(forExecElement);
    forExecElement.contentEditable = true;

    return forExecElement;
}

function SelectContent(element) {
    // first create a range
    var rangeToSelect = document.createRange();
    rangeToSelect.selectNodeContents(element);
    // select the contents
    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(rangeToSelect);
}

//复制 粘贴结束

/********增加多行商品*******************/
var totalnum = 1;
function showaddgoodsSKU(t) {
    var inputn = document.getElementById(t);
    var str = inputn.innerHTML;
    var num = 1;
    for (var i = 1; i <= num; i++) {
        totalnum = totalnum + i;
        str += "<tr id=las" + totalnum + ">";
        str += "<td>";
        str += "商品编号<input type=\"text\" name=\"ordergoodsno[" + totalnum + "]\" id=\"ordergoodsno\" onBlur=\"getstatusgoods(this)\" class=\"width100\" /> 订购数量 <input type=\"text\" name=\"ordergoodsnoNum[" + totalnum + "]\" id=\"ordergoodsnoNum\" class=\"width100\" />  销售金额 <input type=\"text\" name=\"ordergoodsnoPrice[" + totalnum + "]\" id=\"ordergoodsnoPrice\" class=\"width100\" />&nbsp;<a href=javascript:void(0) onclick=delfileinput(" + totalnum + ") class=\"btn btn_book\"><span>移除</span></a></td>";
        str += "</tr>";
    }
    $("#" + t).html(str);

}
function getstatusgoods(e)
{
	var goods = e.value;
	if(goods)
	{
		//判断是否存在该SKU
		 $.post("/order/ajaxbutton", {"op": "getgoodssku", "val": goods},
                function (data) {
                    if (data.code == 201) {
                     e.value = '';
					   alert(data.txt);
                    }

                }, "json");
	}
}
function addgoods(orderID) {
    $("#addgoodsorderID").val(orderID);
    $('#addattributeform').modal('show');

}

function AWSgoodssubmit(f, t,c) {
    var tst = ct = tct = 0;
    var inputArray = $("input[id='ordergoodsno']");//取到所有的input text 并且放到一个数组中
    inputArray.each(//使用数组的循环函数 循环这个input数组
        function () {
            var input = $(this);//循环中的每一个input元素
            if (input.val() == "") {
                tst = 1;
            }
        }
    )

    var inputArray = $("input[id='ordergoodsnoNum']");//取到所有的input text 并且放到一个数组中
    inputArray.each(//使用数组的循环函数 循环这个input数组
        function () {
            var input = $(this);//循环中的每一个input元素
            if (input.val() == "") {
                ct = 1;
            }
        }
    )
    var inputArray = $("input[id='ordergoodsnoPrice']");//取到所有的input text 并且放到一个数组中
    inputArray.each(//使用数组的循环函数 循环这个input数组
        function () {
            var input = $(this);//循环中的每一个input元素
            if (input.val() == "") {
                tct = 1;
            }
        }
    )
    if (tst == 1) {
        alert("所有的商品编号必须填写完整!");
        return false;
    }
    if (ct == 1) {
        alert("所有的订购数量必须填写完整!");
        return false;
    }
    if (tct == 1) {
        alert("所有的销售金额必须填写完整!");
        return false;
    }
	$('#' + t).modal('hide');
	if(c==1)
	{
		showNeworderGoods();
		
	}else{
		
		AWS.ajax_post($('#' + f));
	}

}

//新订单添加商品
function showNeworderGoods()
{
	var vote_arr = $('[id=ordergoodsno]');
	var idarr = new Array();
	var i=0;
	var ordergoodsno="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	       idarr[i] = vote_arr[j].value;
		   ordergoodsno += vote_arr[j].value+",";	//商品信息
		   i++;
	}

	var vote_arr = $('[id=ordergoodsnoNum]');
	var idarr = new Array();
	var i=0;
	var ordergoodsnoNum="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	       idarr[i] = vote_arr[j].value;
		   ordergoodsnoNum += vote_arr[j].value+",";	//商品数量
		   i++;
	}

	var vote_arr = $('[id=ordergoodsnoPrice]');
	var idarr = new Array();
	var i=0;
	var ordergoodsnoPrice="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	       idarr[i] = vote_arr[j].value;
		   ordergoodsnoPrice += vote_arr[j].value+",";	//商品价格
		   i++;
	}
	 $.post("/order/ajaxbutton", {"op": "addorderNewgoods","ordergoodsnoPrice":ordergoodsnoPrice,"ordergoodsnoNum":ordergoodsnoNum,"ordergoodsno":ordergoodsno},
                function (data) {
                    if (data) {
						var tmp = "";
                        for (var s = 0; s < data.length;s++) {
							tmp += '<tr>'
							tmp += "<td height=58><input type=\"hidden\" name=\"goods_id[]\" value=\""+data[s].goods_id+"\"><input type=\"hidden\" name=\"goods_sku[]\" value=\""+data[s].goods_sku+"\"><input type=\"hidden\" name=\"nums[]\" value=\""+data[s].nums+"\"><input type=\"hidden\" name=\"price[]\" value=\""+data[s].Price+"\"><font color=\"#6666FF\">" + data[s].goods_id + "</font></a></td><td height=58><font color=\"#6666FF\">" + data[s].goods_sku + "</font></a></td><td  title=" + data[s].goods_name + ">" + data[s].goods_name + "</td><td>" + data[s].nums + "</td><td>" + data[s].Price + "</td>";
							tmp += "</tr>";
						}
                    }
					$("#addnewordergoodshtml").html(tmp);

                }, "json");
}
//删除商品
function delordersellgoods(orderID) {

    if (confirm("你确认删除所选商品吗?")) {
        var str = selectallpro();
        if (str != false) {
            $.post("/order/ajaxbutton", {"op": "delordersellgoods", "str": str, "orderID": orderID},
                function (data) {
                    if (data == 200) {
                        window.location.href = "/orderlist/editorder?order_id=" + orderID + "&mod";
                    }

                }, "json");


        }
    }

}
function deleteorder()
{
	 if (confirm("你确认删除所选订单吗?只允许删除已作废订单")) {
        var str = selectallpro();
        if (str != false) {
            $.post("/order/ajaxbutton", {"op": "deleteorder", "str": str},
                function (data) {
                    if (data == 200) {
                        window.location.href = "/orderlist/orderlist?status=6";
                    }

                }, "json");


        }
    }
}
//拆分订单
function chatotalgoods(orderID) {
    if (confirm("你确认将所选商品拆分吗?")) {
        var str = selectallpro();
        if (str != false) {
            $.post("/order/ajaxbutton", {"op": "chatotalgoods", "str": str, "orderID": orderID},
                function (data) {
                    if (data.code == 200) {
                        window.location.href = "/orderlist/editorder?order_id=" + data.txt + "&mod";
                    }
                    if (data.code == 201) {
                        alert("更新出错！请联系管理员！");
                        return;
                    }

                }, "json");


        }
    }
}

//修改订单
function saveform() {
    $("#editForm").submit();
}

//合并订单
function jsmergeorder() {
    if (confirm("你确认将所选订单合并吗?")) {
        var str = selectallpro();
        if (str != false) {
            $.post("/order/ajaxbutton", {"op": "jsmergeorder", "str": str},
                function (data) {
                    if (data.code == 200) {
                         window.location.href = "/orderlist/editorder?order_id=" + data.txt + "&mod";
                        return;
                    }
                    if (data.code == 201) {
                        alert(data.txt);
                        return;
                    }

                }, "json");
        }
    }

}

//保存订单

function saveorderform() {

    $("#editForm").submit();

}


//查询订单

function chengprinttype(type, value) {

    //$("#status").val(0);

    if (type == "overweight") {

        $("#isow").val(1);

    }

    if (type == "is_nodelivery") {

        $("#isno").val(1);

    }

    if (type == "is_que") {
        $("#que").val(value);
    }
	 if (type == "orderproperty") {
        $("#isf").val(1);
    }


    $("#search").submit();


}

//作废订单
function toDisabledOrder(action,type){
	$('#DisabledOrderDiv').modal('show');
}

//修改状态
function changorderstatusPro(action, type) {
    var str = selectallpro();
    if (str != false) {
		var arr = str.split(',');
		var num = arr.length-1;
		if(type==4)
		{
			var title="请注意！手工标已发货，不会减少库存！\r\n";
		}else{
			var title = "";
		}
        if (confirm(""+title+" 确认将选中的 [ "+num+" ]个订单，修改状态? \r\n")) {
            $.post("/orderlist/ajaxbutton", {"op": "changstatusPro", "order_id": str, "action": action, "type": type},function (data) {
				if (data.code == 201) {
					alert(data.txt);
					return;
				}
				else {
                    if(data.overseaID){
                        $.post("/orderexcel/ajaxbutton", {"op": "cancelOrderOversea", "order_id": data.overseaID,"depose":1},
                            function (result) {
                            }, "json");
                    }
					window.location.href =  data.url;
				}
			},"json");
        }
    }
}

function executeDisabledOrder(){
	var trade_numbers=$("#trade_numbers").val();
	var arry = trade_numbers.split("\n");//以换行符为分隔符将内容分割成数组
	var trade_no='';
	for(var i=0;i<arry.length;i++){
		if(arry[i]!=''){
			trade_no+=arry[i]+',';		
		}
	}
	if(trade_no==''){
		//alert("你还没有输入要作废的订单交易号");
		//return;
	}
	if (confirm("确认将其中交易号为"+trade_no+"的订单作废?")) {
		$("#trade_id_str").val(trade_no);
		$("#DisabledOrderform").submit();
		
		/*
		$.post("/Expressshipment/disableOrder", {"op": "changstatusPro", "trade_id_str": trade_no, "action":"order_status", "type":6},function (data) {
			if (data.code == 201) {
				alert(data.txt);
				return;
			}else {
				alert("提交成功");
				$('#DisabledOrderDiv').modal('hide');
			}
		},"json");*/
	}
}


function changorderstatus(action, order_id, type) {

    if (confirm("你确认修改状态?")) {

        $.post("/orderlist/ajaxbutton", {"op": "changstatus", "order_id": order_id, "action": action, "type": type},
            function (data) {
                    if(data==200){
                        window.location.href = "/orderlist/editorder?order_id=" + order_id;
                    }else{
                        $.post("/orderexcel/ajaxbutton", {"op": "cancelOrderOversea", "order_id": data,"depose":1},

                            function (result) {
                                window.location.href = "/orderlist/editorder?order_id=" + order_id;
                            }, "json");

                    }

            }, "json");
    }

}


function batchExpress() {
    var winWidth = window.screen.width;
    var winHeight = window.screen.height;
    var newWidth = 1000;
    var newHeight = 750;
    var url = "/orderlist/ajaxbutton?op=batchExpress";
    window.open(url, '_blank', 'height=' + newHeight + ',width=' + newWidth + ',top=10,left=' + (winWidth - newWidth) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
}

//待审查的订单，修改成正式订单
function YesOrderData(id)
{
	 $.post("/orderlist/ajaxbutton", {"op": "YesOrderData", "order_id": id},
		function (data) {
			window.location.href = "/orderlist/editorder?order_id=" + id;
		}, "json");
}

//待审查订单，添加新的商品
function addnewgoods(goodsno)
{
	 $.post("/orderlist/ajaxbutton", {"op": "addnewgoods", "goodsno": goodsno},
		function (data) {
		 if(data.code==201)
		 {
			 window.open("/product/addprodct?sku="+data.goods+"", '_blank');
		 }
		 if(data.code==202)
		 {
			var tmp="";
			var goods = data.goodslist;
			tmp += "<tr><td colspan=\"4\" align='right'><button type=\"button\" class=\"btn btn-primary\" onClick=\"window.open('/product/addParentProduct?pid="+data.parentID+"&goodsno="+goodsno+"', '_blank')\" > 确定添加同类商品 </button><button type=\"button\" class=\"btn btn-primary\" onClick=\"window.open('/product/addprodct', '_blank')\" > 添加新的商品 </button></td></tr>";
			 for (var i = 0; i < goods.length; i++) {
                    tmp += '<tr>'
                    tmp += "<td height=58 width=200 style=\"width: 150px; overflow:hidden;white-space:nowrap; text-overflow:ellipsis;\">名称：<span  ><a href=/product/productlist?other="+goods[i].goods_parent_sku +" target=_thank><font color=\"#6666FF\">" + goods[i].goods_name + "</font></a></span></a></td><td>编号：" + goods[i].goods_sku + "</td><td>同类编号：" + goods[i].goods_parent_sku + "</td>";
                    tmp += "</tr>";
					

                }
				 
			$("#addnewgoodslist").modal('show');
			$("#shownewgoodslist").html(tmp);
		 }
			
		}, "json");
}

function paypalrefund(order_id,order_sn,moneytype,alloriginsale)
{
	$("#paypal_order_sn").val(order_sn);
	$("#paypal_order_id").val(order_id);
	$("#paypal_alloriginsale").val(alloriginsale);
	$("#refund_moneytype").html("<font color=red>【"+moneytype+"】</font>");
	
	$("#addpalpayrefund").modal('show');
}
function savepayrefund()
{
	var order_sn = $("#paypal_order_sn").val();
	var paypal_alloriginsale = $("#paypal_alloriginsale").val();
	var refund_money = $("#refund_money").val();
	var paypal_order_id = $("#paypal_order_id").val();
	var refund_reason = $("#refund_reason").val();
    var otherpaypal = $("#otherpaypal").val();
    var ourpaypal = $("#ourpaypal").val();
	if(refund_money =='')
	{
		alert('请输入退款金额');
		$("#refund_money").focus();
		return false;
	}
	if(refund_reason =='')
	{
		alert('请输入退款理由');
		$("#refund_reason").focus();
		return false;
	}
	if(parseFloat(refund_money) > parseFloat(paypal_alloriginsale))
	{
		alert('需要退款的金额不能大于原始金额');
		$("#refund_money").focus();
		return false;
	}
	 $.post("/orderlist/ajaxbutton", {"op": "savepayrefund", "order_id": paypal_order_id,"refund_money":refund_money,"refund_reason":refund_reason,"otherpaypal":otherpaypal,"ourpaypal":ourpaypal},
		function (data) {
			window.location.href = "/orderlist/editorder?order_id=" + paypal_order_id;
			
		}, "json");
}
function getshopName()
{
	var platformID = $("#platformID").val();
	
	if(platformID)
	{
		 $.post("/orderlist/ajaxbutton", {"op": "getshoplist", "platformID": platformID},
		 function (data) {
			 if(data)
			 {
				 var tmp="<option>店铺</option>";
				 for (var i = 0; i < data.length; i++) {
                    tmp += '<option value='+data[i].id+'>'+data[i].name+'</option>'
					
                }
				$("#shopname").html(tmp);
			 }
		}, "json");
	}
}


function Bulkchanges()
{
	var winWidth = window.screen.width;
    var winHeight = window.screen.height;
    var newWidth = 1000;
    var newHeight = 750;

	var vote_arr = document.getElementsByName("ppid[]");
	var idarr = new Array();
	var i=0;
	var str="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == true)
	   {
	       idarr[i] = vote_arr[j].value;
		   str += vote_arr[j].value+",";
		   i++;
	   }
	   
	}
	
    var url = "/orderlist/ajaxbutton?op=Bulkchanges&str="+str+"";
    window.open(url, '_blank', 'height=' + newHeight + ',width=' + newWidth + ',top=10,left=' + (winWidth - newWidth) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');
	//$("#Bulkchanges").modal('show');
}


function repeatexpress(t)
{
	if(confirm("确定设置选中订单重新交运吗？")){
	  var str = selectallpro();
	 $.post("/order/ajaxbutton", {"op": "repeatexpress", "orderType": t,"orderID":str},
		 function (data) {
			 if(data)
			 {
				window.location.href = data;
			 }
		}, "text");
	}
}

function selectcountry(ts)
{
	var country = $("#country").val();
	$.post("/order/ajaxbutton", {"op": "getcountry", "country": country},
	function (data) {
	 if(data==201)
	 {
		alert("不存在的国家名称，请认真填写国家");
		$("#country").val(ts);
		return;
	 }
	}, "json");
}


function outexpressexcel(t)
{
	var url = "/order/ajaxbutton?op=outexpressexcel&types="+t+"";
	var winWidth = window.screen.width;
    var winHeight = window.screen.height;
    var newWidth = 1000;
    var newHeight = 750;


    window.open(url, '_blank', 'height=' + newHeight + ',width=' + newWidth + ',top=10,left=' + (winWidth - newWidth) / 2 + ',toolbar=no,menubar=no,scrollbars=yes,resizable=no,loocation=no,status=no');


}


//撤销海外仓订单
function cancelOrderOversea() {

    var str = selectallpro();

    if (str != false) {
        var arr = str.split(',');
        var num = arr.length-1;
        if (confirm("确认将选中的 [ "+num+" ]个订单，撤销海外仓发货?")) {

            //$.post("/orderlist/ajaxbutton", {"op": "cancelOrderOversea", "order_id": str},
            $.post("/orderexcel/ajaxbutton", {"op": "cancelOrderOversea", "order_id": str},

                function (data) {
                    if (data.code == 201) {
                        alert(data.txt);
                        return;
                    }
                    else {
                        //window.location.href =  data.url;
                        alert(data.txt);
                        location.reload();
                    }

                }, "json");

        }

    }

}
//海外仓  提交海外仓订单
function showSubmitOrderOversea() {

    var str = selectallpro();
    //var url ="/orderlist/ajaxbutton?op=doSubmitOrderOversea";
    var url ="/orderexcel/ajaxbutton?op=doSubmitOrderOversea";
    $("#overseaattributeform").attr("action",url);
    if(str !=false){
        $("#overseaorderlistst").val(str);
        $('#overseaexpressform').modal('show');
    }
    //$('#overseaexpressform').modal('show');
}
//海外仓  仓库变化，货运方式跟着变化
function changeWarehouse() {
    var deliveroversea = $("#deliveroversea").val();
    $("#transportoversea").empty();
    //英华英国仓
    if(deliveroversea==1){
        //货运方式
        $("#transportoversea").append("<option value='YH2TK'>英国 Royal Mail 2nd Class TR48</option>");
    }
    //英华德国仓
    if(deliveroversea==2){
        $("#transportoversea").append("<option value='DHLPEU'>DE DHL Paket</option>");
        $("#transportoversea").append("<option value='DPDEU'>DE DPD</option>");
        $("#transportoversea").append("<option value='DPORD'>DE DP Letter</option>");
    }
    //EZGO美国仓
    if(deliveroversea==3){
        $("#transportoversea").append("<option value='UPS-G-I'>US UPS Ground</option>");
        $("#transportoversea").append("<option value='USPS-P'>US USPS Priority</option>");
    }
    //万邑通美西仓
    if(deliveroversea==4){

    }

}
//海外仓  提交海外仓订单
function submitOrderOversea() {
    var overseaorderlistst = $("#overseaorderlistst").val();
    if(!overseaorderlistst){
        alert("订单号不能为空");return false;
    }
    var deliveroversea = $("#deliveroversea").val();
    if(!deliveroversea){
        alert("发货仓库不能为空");return false;
    }
    var transportoversea = $("#transportoversea").val();
    if(deliveroversea==5 || deliveroversea==4 || deliveroversea==6){

    }else{
        if(!transportoversea){
            alert("货运方式不能为空");return false;
        }
    }
    var url ="/orderexcel/ajaxbutton?op=doSubmitOrderOversea";
    $("#overseaattributeform").attr("action",url);
    $('#overseaexpressform').modal('hide'); //关闭提交框
    $('#overseaattributeform').submit(); //提交相关数据

}

//订单池 导入EXCEL模块框
function OrderIn() {
    $('#excelorderform').modal('show');
}
//导入excel
function doImportExcel() {
    var shopId = $("#shopId").val();
    //if(!shopId){
     //   alert("未选择任何店铺");return false;
   // }
    //var url ="/orderlist/ajaxbutton?op=doImportExcelOrder&shopId="+shopId;
    var url ="/orderexcel/ajaxbutton?op=importExcelOrder";
    $("#excelattributeform").attr("action",url);
    $('#excelorderform').modal('hide');
    $('#excelattributeform').submit(); //提交相关数据
}


function showshoeschima(rec_id)
{
	var varcha1	= $("#varcha"+rec_id).val();
	if(varcha1 == 1)
	{
		 $("#chimacustom1"+rec_id).show();
		 $("#chimacustom2"+rec_id).hide();

	}
	else{
		  $("#chimacustom1"+rec_id).hide();
		  $("#chimacustom2"+rec_id).show();
	}
}

function saveshoesSize(rec_id,order_id)
{
	var custom	= $("#varcha"+rec_id).val();
	if(custom==1){
	 var shoes_size = $("#varcha2"+rec_id).val();
		//均码 保存尺寸
		$.post("/order/ajaxbutton", {"op": "saveshoesSize", "rec_id": rec_id,"order_id":order_id,"custom":custom,"shoes_size":shoes_size},
		function (data) {
		 
		}, "json");
	}
}
function saveshosecustom(t,rec_id,order_id)
{
	//定制
	var custom	= $("#varcha"+rec_id).val();
	if(custom==2){
		var varcha3 =$("#varcha3"+rec_id).val();
		var varcha4 =$("#varcha4"+rec_id).val();
		var varcha5 =$("#varcha5"+rec_id).val();
		var varcha6 =$("#varcha6"+rec_id).val();
		var varcha7 =$("#varcha7"+rec_id).val();
		var varcha8 =$("#varcha8"+rec_id).val();
		var varcha9 =$("#varcha9"+rec_id).val();
		var varcha10 =$("#varcha10"+rec_id).val();
		var varcha11 =$("#varcha11"+rec_id).val();
		
		if(varcha3 =='0' || varcha4 =='')
		{
			alert('性别和鞋码必填');
			return;
		}


		$.post("/order/ajaxbutton", {"op": "saveshoesSize", 
			"rec_id": rec_id,
			"order_id":order_id,
			"custom":custom,
			"varcha3":varcha3,
			"varcha4":varcha4,
			"varcha5":varcha5,
			"varcha6":varcha6,
			"varcha7":varcha7,
			"varcha8":varcha8,
			"varcha9":varcha9,
			"varcha10":varcha10,
			"varcha11":varcha11
			},
		function (data) {
		}, "json");
	}
}